﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GrabObject : MonoBehaviour {
    public string onGrabbedOperationName;
    public bool backToParent = false;
    protected Transform parent;
    protected Vector3 originalPos;
    protected Quaternion originalRot;
    bool grabbed = false;
    protected virtual void Awake()
    { 
        parent = transform.parent;
        originalPos = transform.localPosition;
        originalRot = transform.localRotation;
    }
    // Use this for initialization
    protected virtual void Start()
    {
        Active(false);
    }

    private void LateUpdate()
    {
        if (!grabbed && backToParent)
        {
            transform.parent = parent;
            transform.localPosition = originalPos;
            transform.localRotation = originalRot;
        }
    }

    public virtual void Active(bool active)
    {
    }

    protected virtual void OnGrabbed()
    {
    }

    protected virtual void OnUngrabbed()
    {
    }
}
